<!DOCTYPE html>
<html lang="zh-cn">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<include file="Widget/head" />
	<link rel="stylesheet" href="__PUBLIC__/kindeditor-4.1.10/themes/default/default.css" />
	<script charset="utf-8" src="__PUBLIC__/kindeditor-4.1.10/kindeditor-min.js"></script>
	<script charset="utf-8" src="__PUBLIC__/kindeditor-4.1.10/lang/zh_CN.js"></script>
	<script type="text/javascript">
	var queryParams = {ajax:'y',cid:"{$cate}"};
	var myeditor;
	$(function(){
		var tb_search = document.getElementById('tb_search');
		queryParams.keyword = tb_search.keyword.value;
		$('#dg').datagrid({
			iconCls: 'icon-save',
			singleSelect: true,
			pagination:true,
			cache:false,
			method:'get',
			url: "{:U('lists')}" ,
			columns:[[
					{field:'mname',title:'商家账户',width:100,align:'center',halign:'center'},  
					{field:'title',title:'任务标题',width:300,halign:'center'},
					{field:'catename',title:'任务类型',width:100,align:'center',halign:'center'},
					{field:'price',title:'任务总价',width:100,align:'center',halign:'center'},
					{field:'yongjin',title:'任务佣金',width:100,align:'center',halign:'center'},
					{field:'picurl',title:'缩略图',width:100,align:'center',halign:'center',
						formatter:function(value,row,index){
							if (value) return '<img src="'+value+'" width="80px" height="60px" />';
							else return '<img src="__IMG__/nopic.jpg" width="80px" height="60px" />';
						}
					},
					{field:'zhuangtai',title:'当前状态',width:80,align:'center',halign:'center'},
					{field:'time_type',title:'更新时间',width:130,align:'right',halign:'center'},
					{field:'status',title:'显示',width:50,align:'center',halign:'center',
						formatter:function(value,row,index){
							if (value>0) {
								return '<a href="javascript:void(0)" onclick="state('+row.id+')"><span class="diyico icon-ok">&nbsp;</span></a>';
							}else {
								return '<a href="javascript:void(0)" onclick="state('+row.id+')"><span class="diyico icon-disable">&nbsp;</span></a>';
							}
						}
					},
			]],
			queryParams: queryParams,
			pageSize: {$_rows} ,
			pageNumber: {$_page},
			toolbar: '#tb',
			onDblClickRow: function() {
				editRow();
			}
		});
		var pager = $('#dg').datagrid('getPager');//分页对象
		pager.pagination({
			displayMsg:''
		});
	});
	//状态切换
	function state(id) {
		$('#dg').datagrid('loading');
		$.ajax({
			cache: false,
			type: "post",
			url: "{:U('state')}",
			data: {id:id},
			async: true, //同步请求, 其它操作必须等待请求完成才可以执行
			success: function(dd) {
				$('#dg').datagrid('reload');
				//$('#dg').datagrid('loaded');
			}
		});
	}
	function typechange(rec) {
		$('#tb_search').form('submit',{
			onSubmit:function(){
				//做数据处理
				goclear();
				$('#tb_search').form('load',{cate:rec.value});
				queryParams.cate = rec.value;
				$('#dg').datagrid('load',queryParams);
				return false;
			}
		});
	}
	//编辑记录
	function editRow() {
		var row = $('#dg').datagrid('getSelected');
		//alert(JSON.stringify(row));
		if (row){
			$('#formRow').form('load',row);
			$("#editRow").dialog({
				width: 600,
				title: row.title,
				iconCls: "icon-save",
				cache: false,
				modal: true,
				buttons:[{
					iconCls: 'icon-save',
					text: "修改保存",
					handler:function(){
						$('#formRow').form('submit',{
							url: "{:U('update')}",
							onSubmit: function(param){
								if ($(this).form('validate')) {
									$("body").easyMask('show');
									param.id = row.id;
								}else return false;
							},
							success: function(dd) {
								$('#dg').datagrid('reload');
								$("body").easyMask('hide');
								dd = eval('(' + dd + ')');
								if (dd.status>0) {
									$.messager.alert('',dd.info,'info');
									$("#editRow").dialog('close');
								}else $.messager.alert('',dd.info,'error');
							}
						});
					}
				},{
					iconCls: 'icon-cancel',
					text: "关闭",
					handler:function(){
						$("#editRow").dialog('close');
					}
				}],
				onBeforeClose:function(){
					KindEditor.remove('#editor_content');
				}
			});
		}
	}
	//筛选查询
	function gosearch() {
		$('#tb_search').form('submit',{
			queryParams: {ajax:'y',cid:"{$cate}"},
			onSubmit:function(){
				//做数据处理
				queryParams.keyword = this.keyword.value;
				$('#dg').datagrid('load',queryParams);
				return false;
			}
		});
	}
	function goclear() {
		$('#tb_search').form('clear');
		queryParams = {ajax:'y',cid:"{$cate}"};
	}
	//删除记录
	function delRow() {
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$.messager.confirm('', '确认删除此条信息吗?', function(r) {
				if (r){
					$("body").easyMask('show');
					$.ajax({
						cache: false,
						type: "post",
						url: "{:U('delete')}",
						data: {id:row.id},
						async: true, //同步请求, 其它操作必须等待请求完成才可以执行
						success: function(dd) {
							$('#dg').datagrid('reload');
							$("body").easyMask('hide');
							$.messager.alert('',dd.info,'info');
						},
						error: function() {
							$("body").easyMask('hide');
						}
					});
				}
			});
		}
	}
	//增加记录
	function addRow(){
		var row = $('#dg').datagrid('getSelected');
		$("#editRow").dialog({
			width: 300,
			title: "新增文章信息",
			iconCls: "icon-add",
			cache: false,
			modal: true,
			buttons:[{
				iconCls: 'icon-add',
				text: "新增保存",
				handler:function(){
					$('#formRow').form('submit',{
						url: "{:U('insert')}",
						onSubmit: function(param){
							if ($(this).form('validate')) {
								$("body").easyMask('show');
								param.cate = "{$cate}";
							}else {
								return false;
							}
						},
						success: function(dd) {
							$('#dg').datagrid('reload');
							$("body").easyMask('hide');
							dd = eval('(' + dd + ')');
							if (dd.status>0) {
								$.messager.alert('',dd.info,'info');
								$("#editRow").dialog('close');
							}else {
								$.messager.alert('',dd.info,'error');
							}
						}
					});
				}
			},{
				iconCls: 'icon-cancel',
				text: "关闭",
				handler:function(){
					$("#editRow").dialog('close');
				}
			}],
			onClose: function(){
				$('#formRow').form('clear');
			}
		});
	}
	</script>
</head>

<body class="easyui-layout">
<table id="dg" title="" style="width:100%;height:100%" border="0"></table>

<div id="tb" class="datagrid-toolbar">
	<form id="tb_search" method="get">
	<table cellspacing="0" cellpadding="3">
	<tr>
		<td><a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" onclick="editRow();">查看编辑</a></td>
		<td><span class="datagrid-btn-separator"></span></td>
		<td>
			类型: 
			<select class="easyui-combobox" name="cate" data-options="value:'{$cate}',editable:false,onSelect:typechange" style="width:80px;">
				<option value="0">所有</option>
				<option value="1">垫付单</option>
				<option value="2">立返单</option>
				<option value="3">远程单</option>
				<option value="4">浏览单</option>
			</select>
		</td>
		<td>关键字: <input name="keyword" class="easyui-textbox" style="width:100px" value="{$keyword}"></td>
		<td>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="gosearch()">搜索</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-undo" onclick="goclear()">清空</a>
		</td>
	</tr>
	</table>
	</form>
</div>

<div id="editRow">
<form id="formRow" method="post" enctype="multipart/form-data">
	<table cellspacing="0" cellpadding="3">
		<tr>
			<td>任务标题:</td>
			<td colspan="5"><input class="easyui-textbox" style="width:100%;" type="text" name="title" readonly></td>
		</tr>
		<tr>
			<td>任务类型:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="catename" readonly></td>
			<td>任务总价:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="price" readonly></td>
			<td>发布数量:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="number" readonly></td>
		</tr>	
		<tr>
			<td>验证地址:</td>
			<td colspan="5"><input class="easyui-textbox" style="width:100%;" type="text" name="url" readonly></td>
		</tr>
		<tr>
			<td>关键字:</td>
			<td colspan="5"><input class="easyui-textbox" style="width:100%;" type="text" name="keywords" readonly></td>
		</tr>
		<tr>
			<td>任务要求:</td>
			<td colspan="5"><input class="easyui-textbox" style="width:100%;" type="text" name="content" readonly></td>
		</tr>
		<tr>
			<td>刷手星级:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="xinyong" readonly></td>
			<td>追加金豆:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="zhuijia" readonly></td>
			<td>货比数量:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="huobi" readonly></td>
		</tr>
		<tr>
			<td>主宝数量:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="znum" readonly></td>
			<td>主宝浏览:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="zliulan" readonly></td>
			<td>副宝数量:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="fnum" readonly></td>
		</tr>
		<tr>
			<td>双收藏:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="shoucang" readonly></td>
			<td>客服假聊:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="liao" readonly></td>
			<td>星级评价:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="xing" readonly></td>
		</tr>
		<tr>
			<td>内容评价:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="ping" readonly></td>
			<td>模板名称:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="moban" readonly></td>
			<td></td>
			<td></td>
		</tr>
		<tr>
			<td>每单佣金:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="yongjin" readonly></td>
			<td>共计扣除:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="kouchu" readonly></td>
			<td>发布商户:</td>
			<td><input class="easyui-textbox" style="width:100px;" type="text" name="mname" readonly></td>
		</tr>
	</table>
</form>
</div>
</body>
</html>